package student.aistar.day11;


import student.aistar.day10.Book;

import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListMethod {
    public static void main(String[] args) {
        Book b1 = new Book(1,"1001","java",100.0d);
        Book b2 = new Book(2,"1002","java",200.0d);
        Book b3 = new Book(3,"1003","java",100.0d);
        Book b4 = new Book(4,"1004","python",300.0d);

        LinkedList<Book> list = new LinkedList<>();
        list.add(b1);
        list.add(b2);

        //将元素添加到头部
        list.addFirst(b3);
        //在链表的尾部进行添加节点
//        list.addLast(b4);

        //push一般和pop一起使用
        //push - 压入栈顶
        //list.push(b4)
        //pop - 弹出栈顶元素, 并且返回这个弹出的元素
//        System.out.println(list.pop());

        //删除第一个元素
//        list.removeFirst();
        //删除最后一个元素
//        list.removeLast();


        //offer offerFirst offerLast
        //add addFirst addLast
//        list.offer(b4);

        System.out.println(list.getFirst());

        System.out.println("=======");
        //遍历方式和ArrayList一模一样
        //迭代器
        Iterator<Book> iterator = list.iterator();//获取迭代器对象
        while (iterator.hasNext()){
            Book next = iterator.next();
            System.out.println(next);
        }


    }
}
